/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;
import java.util.Scanner;

/**
 * <p>Project: javaseapp - Exce1
 * <p>Powered by webrx On 2021-08-09 10:12:05
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Exce2 {
    public static void main(String[] args) {
        Random rand = new Random();
        int num = rand.nextInt(100) + 1;
        Scanner sc = new Scanner(System.in);


        int temp = 0;
        int t = 0;
        while (true) {
            //sc = new Scanner(System.in);
            System.out.print("请输入数字：");
            try {
                temp = sc.nextInt();
            } catch (Exception e) {
                System.out.println("请认真输入，请必须输入数字。");
                sc.next();
                //sc.nextLine();
                //也可以在每次循环时 实现化一下Scaner
                continue;
            } finally {
                t++;
            }
            System.out.println("t = " + t);
            if (temp > num) {
                System.out.println("太大了");
            } else if (temp < num) {
                System.out.println("太小了");
            } else {
                System.out.println("恭喜，猜对了.");
                break;
            }
        }
    }
}
